/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vista;

import java.awt.Color;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import javax.swing.ImageIcon;

/**
 *
 * @author william
 */
public class TransferableImage implements Transferable {

    protected static DataFlavor imageFlavor =
            new DataFlavor(ImageIcon.class, "An image object");
    protected static DataFlavor[] supportedFlavors = {
        imageFlavor,
        DataFlavor.stringFlavor,};
    ImageIcon image;

    public TransferableImage(ImageIcon image) {
        this.image = image;
    }

    public DataFlavor[] getTransferDataFlavors() {
        return supportedFlavors;
    }

    public boolean isDataFlavorSupported(DataFlavor flavor) {
        if (flavor.equals(imageFlavor)
                || flavor.equals(DataFlavor.stringFlavor)) {
            return true;
        }
        return false;
    }

    public Object getTransferData(DataFlavor flavor)
            throws UnsupportedFlavorException {
        if (flavor.equals(imageFlavor)) {
            return image;
        } else if (flavor.equals(DataFlavor.stringFlavor)) {
            return image.toString();
        } else {
            throw new UnsupportedFlavorException(flavor);
        }
    }
}
